import 'package:flutter/material.dart';

class TextFileldDemo extends StatefulWidget {
  TextFileldDemo({Key key}) : super(key: key);
  @override
  _TextFileldDemoState createState() => _TextFileldDemoState();
}

class _TextFileldDemoState extends State<TextFileldDemo> {
  TextEditingController _uname = TextEditingController();
  String text = '';
  @override
  void initState() {
    super.initState();
    // _uname.text = '默认值';
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('TextFileld'),
      ),
      body: Container(
          padding: EdgeInsets.all(10),
          child: Center(
            child: Column(
              children: [
                TextField(
                  controller: this._uname,
                  decoration: InputDecoration(),
                  onChanged: (value) {
                    // print(value);
                    setState(() {
                      this.text = value;
                    });
                  },
                ),
                SizedBox(
                  height: 10,
                ),
                Container(
                  width: double.infinity,
                  child: RaisedButton(
                    child: Text('获取表单值'),
                    onPressed: () {
                      setState(() {
                        this._uname.text += '1';
                      });
                    },
                    textColor: Colors.white,
                    color: Colors.blue,
                  ),
                ),
                Text(this.text),
                TextField(
                  // obscureText: true, //是否为密码框
                  // minLines: 1,
                  // maxLines: 3,  //最大的行数
                  // maxLength: 10, //输入长度
                  maxLines: 3, //多行文本框
                  decoration: InputDecoration(
                      labelText: "账号", // 修饰文字
                      border: OutlineInputBorder(), //边框
                      hintText: '请输入账号', //占位文字
                      icon: Icon(Icons.cached)), //图标
                ),
              ],
            ),
          )),
    );
  }
}
